<?php
/**
 * 模块启动文件
 */
namespace addons\ad;
use system\Addon;

class Ad extends Addon {
    public function getName()
    {
        return 'index';
    }

    public function getVersion()
    {
        return [
            '1.0.0',
        ];
    }

    public function getAuthor()
    {
        return 'Colin';
    }

    public function getDesc()
    {
        return '广告管理';
    }

    public function upgrade(){
    	return [];
	}

    public function install()
    {
        $sql['1.0.0'][] = "CREATE TABLE IF NOT EXISTS `@ad_type`(
id int unsigned not null auto_increment primary key , 
title varchar(40) not null comment '类型名' , 
limit_size tinyint(0) unsigned null default 0 comment '限制大小 0不限制 1限制宽高 2限制正方形' , 
limit_policy text null comment '限制策略' , 
create_time int(10) default 0 comment '添加时间'
)engine=myisam charset=utf8 comment='广告类型表';";
        $sql['1.0.0'][] = "CREATE TABLE IF NOT EXISTS `@index` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(255) DEFAULT NULL COMMENT '标题',
  `type_id` int default null comment '类型ID',
  `image` varchar(100) DEFAULT NULL COMMENT '图片',
  `desc` varchar(255) DEFAULT NULL COMMENT '描述',
  `url` varchar(255) DEFAULT null COMMENT '跳转地址',
  `sort` int(11) DEFAULT NULL COMMENT '排序、越大排在前面',
  `state` tinyint(1) DEFAULT NULL COMMENT '状态 1 显示 0 隐藏 -1 下架',
  `create_time` int(10) DEFAULT NULL COMMENT '创建时间',
  `update_time` int(10) DEFAULT NULL COMMENT '更新时间',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 comment='广告表';";
        return $sql;
    }

    public function uninstall()
    {
        $sql['1.0.0'][] = "DROP TABLE `@ad_type`";
        $sql['1.0.0'][] = 'DROP TABLE `@index`';
        return $sql;
    }

    public function onInitMenu(&$data = []){
        return [
            [
                'name'  => 'ad',
                'title' => '广告管理',
                'icon'  => 'layui-icon-set',
                'list'  => [
                    ['name' => 'ad_type', 'title' => '广告类型', 'auth_name' => 'SysUsers', 'action' => 'index' , 'jump' => '---ad/type'],
                    ['name' => 'ad_list', 'title' => '广告列表', 'auth_name' => 'AuthGroup', 'action' => 'index' , 'jump' => '---ad/index'],
                ]
            ],
        ];
    }
}